package com.qj.yantaishan.controller;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qj.yantaishan.common.core.domain.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.Coupon;
import com.qj.yantaishan.service.ICouponService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 优惠券Controller
 *
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/Coupon")
public class CouponController extends BaseController {
    private String prefix = "yantaishan/Coupon";

    @Autowired
    private ICouponService couponService;

    @GetMapping("list")
    public R coupon(@RequestParam(required = false, defaultValue = "1") Integer currentPage,
                    @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                    Integer status) {
        Map<String, Object> result = couponService.getCouponList(currentPage, pageSize, status);
        return R.ok(result);
    }

    @PostMapping()
    public R newCoupon(@RequestBody Coupon coupon) {
        couponService.addCoupon(coupon);
        return R.ok();
    }

    @GetMapping
    public R coupon(@RequestParam(required = true) Long couponId) {
        return R.ok(couponService.getCouponById(couponId));
    }

    @DeleteMapping()
    public R delete(@RequestParam(required = true) Long couponId) {
        return R.ok(couponService.removeById(couponId));
    }

    @PutMapping()
    public R modify(@RequestParam(required = true) Long couponId) {
        couponService.update(new LambdaUpdateWrapper<Coupon>().set(Coupon::getStatus, 0).eq(Coupon::getId,couponId));
        return R.ok();
    }

}
